package clone;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/15
 */
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Phone phone = new Phone("小米15",3999.0);
        Person p1 = new Person("小王",20,"男",phone);

        //对p1进行克隆 让Person实现Cloneable接口，重写Clone（）方法
        Person p2 =  p1.clone();

        System.out.println("------------克隆后,修改前--------------");
        System.out.println("p1:"+p1);
        System.out.println("p2:"+p2);

        System.out.println("------------克隆后,修改后--------------");
        p1.setAge(30);
        p1.getPhone().setPrice(3000.0);
        System.out.println("p1:"+p1);
        System.out.println("p2:"+p2);

    }
}
